﻿using System;
using CvModel;
using DAL;

namespace LAB3_Cv
{
    public partial class MainWorkAdmin : System.Web.UI.MasterPage
    {
        private Admin _currentAdmin;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["CurrentAdmin"] == null)
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            ShowLoggedInUser();
        }
        private void ShowLoggedInUser()
        {
            ButtonLogout.Visible = true;
            ButtonLogin.Visible = false;
            LoadCurrentUser();
            LabelNameLoggedIn.Visible = true;
            LabelTextLoggedIn.Visible = true;
        }

        public void LoadCurrentUser()
        {
            _currentAdmin = Session["CurrentAdmin"] as Admin;
            Session["Applications"] =
                WorkApplicationsDB.GetAllWorkApplicationsFromApplicant(_currentAdmin.AdminId);
            LabelNameLoggedIn.Text = _currentAdmin.CompanyName;
        }

        protected void ButtonLogout_Click(object sender, EventArgs e)
        {
            Session["SearchString"] = null;
            Session["CurrentAdmin"] = null;
            Session["AdminId"] = null;
            Session["CurrentUser"] = null;
            Session["Applications"] = null;
            Session["WorkAdId"] = null;
            Session["DeletedAd"] = null;
            Session["SelectedCv"] = null;
            Session["PrintCv"] = null;
            Session["CvList"] = null;
            Response.Redirect("~/Default.aspx");
        }
    }
}